#Title[Íu_[Nz[NX^[v]
#Text[̃XyJ[h]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
        let count=0;
        let cx=GetCenterX();
        let cy=GetCenterY();
        let csd     = GetCurrentScriptDirectory;
        let imgBoss =csd~"img\dot_devil.png";
        let name    = "Íu_[Nz[NX^[v";
	let AnimationA=0;
	let AnimationB=0;
	let AnimationC=0;
        let angle = 0;
        let bngle = 0;
	let Motion=0;
	let j=0;
        let imgSPELL =csd~"img\SPELL_H.png";
        let imgAngle2 = 0;
	let shotseA = csd~"se\ShotSE02.wav";
	let shotseB = csd~"se\ShotSE05.wav";

    @Initialize {
    CutIn(YOUMU, name, 0, 0, 0, 0, 0);

        SetLife(3000);
        SetTimer(50);
        SetScore(1000000);
        SetDamageRate(0,0);

        SetInvincibility(0);
        SetShotDirectionType(ABSOLUTE);

        SetInvincibility(0);
        SetMovePosition02(cx,150,60);
	LoadGraphic(imgBoss);
	LoadGraphic(imgSPELL);
	LoadUserShotData(csd~"img\PLUS_shot.txt");
        TAnime1;
    }

        @MainLoop
        {
	imgAngle2++;
	if(imgAngle2>360){imgAngle2=0;}
	if(count==150){
		Motion=1;
		Concentration01(60);
		}
	if(count==200){
		Motion=0;
		j=0;
        	SetDamageRate(100,50);
		}
	if(count>=200&&count%10==0){
		PlaySE(shotseA);
        	FiraShot(3,angle);
        	FiraShot(1.5,-angle);
        	angle=angle+20;
		}
	if(count>=400&&count%50==0){
		PlaySE(shotseB);
		let i=0;
		while(i<18)
		{
        	let shot01 = 1;
        	CreateShotA(shot01,GetX+cos(i*20+bngle)*10,GetY+sin(i*20+bngle)*10,5);
        	SetShotDataA(shot01,0,1,i*20+bngle,0,0,1,91);
        	FireShot(shot01);
        	CreateShotA(shot01,GetX+cos(i*20+bngle)*10,GetY+sin(i*20+bngle)*10,5);
        	SetShotDataA(shot01,0,2,i*20+bngle,0,0,2,91);
        	FireShot(shot01);
		i++;
		}
		bngle=rand(0,360);
		}
	if(count>=400&&count%200==0){
		TAnime2;
		SetMovePositionRandom01(rand(5,150),rand(10,40),2,GetClipMinX()+100,100,GetClipMaxX()-100,175);
		}
	SetCollisionA(GetX(),GetY(),18);
        SetCollisionB(GetX(),GetY(),18);
        count++;
        yield;
        }

        @DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(imgBoss);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetColor(255,255,255);
		SetGraphicAngle(0,0,0);
	if(Motion==0){
		if(int(GetSpeedX())==0)
		{SetGraphicRect(128*AnimationC,128*AnimationB,127+128*AnimationC,127+128*AnimationB);}
		else if(GetSpeedX()>0){SetGraphicRect(256,256+128*AnimationA,383,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
		}
	if(Motion==1){
		if(int(GetSpeedX())==0)
		{SetGraphicRect(0,128*AnimationB,127,127+128*AnimationB);}
		else if(GetSpeedX()>0){SetGraphicRect(256,256+128*AnimationA,383,383+128*AnimationA);}
		else if(GetSpeedX()<0){SetGraphicRect(256,128*AnimationA,383,127+128*AnimationA);}
		DrawGraphic(GetX(),GetY());
		}
	}

	@BackGround
	{
		//wi`
		SetGraphicRect(0,0,81,81);
		SetTexture(imgSPELL);
		SetRenderState(ALPHA);
		SetGraphicScale(12,12);
		SetColor(0,0,100);
		SetAlpha(255);
		SetGraphicAngle(0,0,-imgAngle2*4);
		DrawGraphic(cx,cy);

		SetGraphicScale(7,7);
		SetColor(155,0,155);
		SetAlpha(155);
		SetGraphicAngle(0,0,imgAngle2*3);
		DrawGraphic(cx,cy);

		SetGraphicScale(4,4);
		SetColor(55,55,55);
		SetAlpha(155);
		SetGraphicAngle(0,0,-imgAngle2*2);
		DrawGraphic(cx,cy);

		SetGraphicScale(2,2);
		SetColor(0,0,155);
		SetAlpha(155);
		SetGraphicAngle(0,0,imgAngle2);
		DrawGraphic(cx,cy);
	}
        
        @Finalize
        {
	loop(30)
	{
		angle=rand(0,360);
		CreateItem(ITEM_SCORE,GetX+cos(angle)*rand(35,50),GetY+sin(angle)*rand(35,50));
	}
        } 
	
    	task TAnime1{
			AnimationB=0;
			AnimationC=3;
        		loop(16){yield;}
			AnimationB=1;
        		loop(56){yield;}
			AnimationB=0;
        		loop(8){yield;}
		loop{
			AnimationB=0;
			AnimationC=0;
        		loop(10){yield;}
			AnimationB=1;
        		loop(10){yield;}
			AnimationB=2;
        		loop(10){yield;}
			AnimationB=3;
        		loop(10){yield;}
			}
		}

    	task TAnime2{
			AnimationA=0;
        		loop(10){yield;}
			AnimationA=1;
        		loop(30){yield;}
			AnimationA=0;
        		loop(10){yield;}
		}

    	task FiraShot(speed,angle){
		let obj = Obj_Create(OBJ_SHOT);
		let l = 0;
		ObjShot_SetBombResist(obj,true);
		Obj_SetPosition(obj,GetX+cos(angle)*500,GetY+sin(angle)*500);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,angle+180);
		ObjShot_SetGraphic(obj,81);
		ObjShot_SetDelay(obj,5);
		Obj_SetAutoDelete(obj,false);

	if(Obj_GetX(obj)>GetEnemyX-50&&Obj_GetX(obj)<GetEnemyX+50&&Obj_GetY(obj)>GetEnemyY-50&&Obj_GetX(obj)<GetEnemyY+50){
		Obj_SetAutoDelete(obj,true);
		}
	}
}